package com.ky.pro.java.sharding.ecommerce.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ky.pro.java.sharding.ecommerce.entity.ComOrder;
import com.ky.pro.java.sharding.ecommerce.mapper.ComOrderMapper;
import com.ky.pro.java.sharding.ecommerce.util.ListUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单信息表 服务实现类
 * </p>
 *
 * @author Kevin Dummy
 * @since 2021-12-18
 */
@Service
public class ComOrderServiceImpl extends ServiceImpl<ComOrderMapper, ComOrder> implements IService<ComOrder> {

    public int batchInsertPlus(List<ComOrder> orderList, int batchSize) {

        List<List<ComOrder>> subLists = ListUtil.partListBalanced(orderList, orderList.size() / batchSize);
        return subLists.stream().mapToInt(subList -> baseMapper.insertBatchSomeColumn(subList)).sum();

    }

}
